<template>
  <div style="text-align: right; margin: 20px;">
    <el-button @click="ResDerive">导出</el-button>
  </div>
</template>

<script lang="ts" setup>
import * as XLSX from "xlsx";
import { ElMessage } from 'element-plus';

const props = defineProps<{
  dataList: object;
}>();

const aaa = props.dataList;
console.log(111, aaa);

// 表格导出
const ResDerive = () => {
  const data = XLSX.utils.json_to_sheet(aaa as any); // 使用 [aaa.value] 将数据包装成数组
  const wb = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(wb, data, 'test-data'); // 'test-data' 为定义的表格中表头名
  XLSX.writeFile(wb, 'test.xlsx'); // 'test.xlsx' 为自定义的文件名

  ElMessage({
    message: "导出成功",
    type: 'success',
  });
}
</script>

<style lang="scss" scoped></style>
